package com.lb.service.impl;

import com.lb.entity.TbSalaMovie;
import com.lb.dao.TbSalaMovieDao;
import com.lb.service.TbSalaMovieService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (TbSalaMovie)表服务实现类
 *
 * @author libo
 * @since 2024-09-11 16:43:28
 */
@Service("tbSalaMovieService")
public class TbSalaMovieServiceImpl implements TbSalaMovieService {
    @Resource
    private TbSalaMovieDao tbSalaMovieDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public TbSalaMovie queryById(Integer id) {
        return this.tbSalaMovieDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param tbSalaMovie 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<TbSalaMovie> queryByPage(TbSalaMovie tbSalaMovie, PageRequest pageRequest) {
        long total = this.tbSalaMovieDao.count(tbSalaMovie);
        return new PageImpl<>(this.tbSalaMovieDao.queryAllByLimit(tbSalaMovie, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param tbSalaMovie 实例对象
     * @return 实例对象
     */
    @Override
    public TbSalaMovie insert(TbSalaMovie tbSalaMovie) {
        this.tbSalaMovieDao.insert(tbSalaMovie);
        return tbSalaMovie;
    }

    /**
     * 修改数据
     *
     * @param tbSalaMovie 实例对象
     * @return 实例对象
     */
    @Override
    public TbSalaMovie update(TbSalaMovie tbSalaMovie) {
        this.tbSalaMovieDao.update(tbSalaMovie);
        return this.queryById(tbSalaMovie.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.tbSalaMovieDao.deleteById(id) > 0;
    }
}
